Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
Argumentless nodemon command in npm project does not run value of "main" from package.json

I have an npm project with the following folder structure:

project
├── node_modules
│   └── (node_modles folders)
├── server.js
├── index.js
├── index.html
├── package.json
└── package-lock.json

My index.js is my front end JavaScript code of this little Web app. And my server.js is the back end. I'm using nodemon (version 2.0.16) to run my server.js file, which is a simple Express app:

const express = require('express');
const app = express();
app.listen(4000, () => {console.log('Listening on port 4000')})

To run my server, I run nodemon server.js in my terminal, and my Express app runs correctly. However, the Nodemon docs say:

If you have a package.json file for your app, you can omit the main script entirely and nodemon will read the package.json for the main property and use that value as the app (ref).

So, I figure that if my package.json file looks like this

{
  "main": "server.js",
  "dependencies": {
    "express": "^4.18.1"
  }
}

then I should be able to just run nodemon instead of nodemon server.js, and everything should work the same. However, this is not the case. When I simply run nodemon with this setup, it's apparently trying to run my index.js file regardless of what I have for "main" in my package.json file. Can anyone explain why I can't just run nodemon without arguments in this case?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It appears that if I delete index.js, running the no-argument nodemon command works as expected. However, if there is a file named index.js at the root of the project, then that file will get run no matter what I put for "main" in package.json.

I'm not sure if this is working-as-designed or if it was intended to have the "main" value ignored like this. I couldn't find a mention of the precedence in the docs.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!